﻿namespace WebMarkupMin.WebForms.Pages
{
	using System.Web;
	using System.Web.UI;

	using Core;
	using Core.Minifiers;
	using Web;
	using Web.Helpers;

	/// <summary>
	/// Web Forms page with support of HTML minification and GZIP/Deflate compression
	/// </summary>
	public class MinifiedAndCompressedHtmlPage : MinifiedAndCompressedPageBase
	{
		protected override void Render(HtmlTextWriter writer)
		{
			if (EnableMinification)
			{
				HttpContext context = HttpContext.Current;
				HtmlMinifier htmlMinifier =
					WebMarkupMinContext.Current.Markup.CreateHtmlMinifierInstance();

				RenderWithMarkupMinification(writer, context, htmlMinifier);

				if (WebMarkupMinContext.Current.IsCopyrightHttpHeadersEnabled())
				{
					CopyrightHelper.AddHtmlMinificationPoweredByHttpHeader(context.Response);
				}
			}
			else
			{
				base.Render(writer);
			}
		}
	}
}